/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.ugent.medirem.persistence.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author Thomas Roelens <thomas.roelens@ugent.be>
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Medication.FindAll",
    query = "SELECT m FROM Medication m"),
    @NamedQuery(name = "Medication.Search",
    query = "SELECT m FROM Medication m WHERE m.name LIKE :name")
})
public class Medication implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private double stdDose;
    @ManyToOne
    private Unit unitDose;
    /**
     * Needed for variable dosages that are dependent of measurements
     */
    @ManyToOne
    private MeasurementType measurementType;

    public Medication() {
    }

    public Medication(String name, double stdDose, Unit unitDose) {
        this.name = name;
        this.stdDose = stdDose;
        this.unitDose = unitDose;
    }

    public Medication(String name, double stdDose, Unit unitDose, MeasurementType measurementType) {
        this.name = name;
        this.stdDose = stdDose;
        this.unitDose = unitDose;
        this.measurementType = measurementType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getStdDose() {
        return stdDose;
    }

    public void setStdDose(double stdDose) {
        this.stdDose = stdDose;
    }

    public Unit getUnitDose() {
        return unitDose;
    }

    public void setUnitDose(Unit unitDose) {
        this.unitDose = unitDose;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public MeasurementType getMeasurementType() {
        return measurementType;
    }

    public void setMeasurementType(MeasurementType measurementType) {
        this.measurementType = measurementType;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Medication)) {
            return false;
        }
        Medication other = (Medication) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "be.ugent.medirem.persistence.entity.Medication[id=" + id + "]";
    }
}
